<?php

    // 取得数据表的字段信息
    function fields($tab){
        $q = mysqli_query($this->link, "show full fields from $tab");
        $a = array();
        if($q){
        while($r=mysqli_fetch_assoc($q)){
            $k = $r['Field']; 
            $t['name'] = $k;
            $t['type'] = $r['Type'];
            $t['notnull'] = $r['Null']==='NO';
            $t['default'] = $r['Default'];
            $t['primary'] = $r['Key']==='PRI'; //!empty()
            $t['autoinc'] = $r['Extra']==='auto_increment';
            $t['Comment'] =  $r['Comment'];
            $a[$k] = $t;    
        } }
        return $a;
    }
    // 取得数据库的表信息
    function tables(){
        $dbname = $this->dbName;
        $q = mysqli_query($this->link, "SHOW TABLES FROM $dbname"); 
        $a = array();
        while($r = mysqli_fetch_row($q)){
            $a[] = $r[0]; 
        }
        return $a;
    }
    // 取得数据库的表信息
    function tabinfo(){
        $dbname = $this->dbName;
        $q = mysqli_query($this->link, "SHOW TABLE STATUS");
        $a = array();
        while($r = mysqli_fetch_array($q,1)){
            $a[] = $r; 
        }
        return $a;
    }
    // 取得创建表sql
    function create($tab){ 
        $q = mysqli_query($this->link, "SHOW CREATE TABLE $tab");
        $r = mysqli_fetch_row($q); 
        return $r[1];
    }
  